package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;
import com.kgc.scd.bean.Address;
import com.kgc.scd.service.AddressServiceFeign;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.UserAnno;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: WangKuoKuo
 * @create: 2022-06-14 14:40
 * @description:
 **/
@RestController
@Api(tags = "08、地址管理入口")
public class AddressWebController {

    @Autowired
    private AddressServiceFeign addressServiceFeign;

    /***
     * @author : WangKuoKuo
     * @date   : 2022/6/14/014
     * @param  : [address]
     * @return : com.kgc.scd.util.RequestResult<com.kgc.scd.bean.Address>
     * @description : 新增地址
     */
    @PostMapping("/addAddress")
    @RequestPermission
    @ApiOperation("添加地址")
    public RequestResult<Address> addAddress(@RequestUser UserAnno userAnno,
                                             @RequestBody Address address) {
        address.setAddrUserId(userAnno.getUserId());
        return addressServiceFeign.addAddress(address);
    }

    /**
     * @param : [address]
     * @return : com.kgc.scd.util.RequestResult<com.kgc.scd.bean.Address>
     * @author : WangKuoKuo
     * @date : 2022/6/14/014
     * @description : 删除地址
     */
    @PostMapping("/delAddress")
    @RequestPermission
    @ApiOperation("根据地址id删除地址")
    public RequestResult<String> delAddress(@RequestParam String addrId) {
        return addressServiceFeign.delAddress(addrId);
    }

    /**
     * @param : [address]
     * @return : com.kgc.scd.util.RequestResult<com.kgc.scd.bean.Address>
     * @author : WangKuoKuo
     * @date : 2022/6/14/014
     * @description : 修改地址
     */
    @PostMapping("/modAddress")
    @ApiOperation("修改地址")
    public RequestResult<Address> modAddress(@RequestBody Address address) {

        return addressServiceFeign.modAddress(address);
    }

    /**
     * @param : [addrUserId]
     * @return : com.kgc.scd.util.RequestResult<java.util.List<com.kgc.scd.bean.Address>>
     * @author : WangKuoKuo
     * @date : 2022/6/14/014
     * @description : 查询指定用户的全部地址
     */
    @GetMapping("/listAddress")
    @RequestPermission
    @ApiOperation("查询指定用户的全部地址")
    public RequestResult<List<Address>> listAddress(@RequestUser UserAnno userAnno) {
        return addressServiceFeign.listAddress(userAnno.getUserId());
    }


}
